home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 015a / bootwhat.zip / BOOTMENU.ASM < prev    next >
Assembly Source File  |  1990-12-17  |  5KB  |  235 lines

  1.     PAGE 60,132
  2. ;    bootmenu: BOOT Hard Disk Partition
  3. ;    by Gordon W. Ross, Aug 1990
  4. ;
  5. ;    See the file bootmenu.doc for user instructions.
  6. ;
  7. ;    This version of bootmenu is compatible with SpeedStor.
  8. ;    See the file sstor-bug.txt for the gory details.
  9. ;
  10. ;    The following is an outline of the program:
  11. ;
  12. ;    Relocate self from 0x7c00 to 0x0600
  13. ;    Display partition menu
  14. ;    Prompt for and read user selection
  15. ;
  16. ;    Boot from the selected partition:
  17. ;    (was selected by user, or was active)
  18. ;    Read first sector of selected partition into 0x7c00
  19. ;    Verify good second-stage boot sector (magic word)
  20. ;    Set-up correct register values and jump to it.
  21. ;
  22.  
  23. CODEORG    equ 0600h    ; offset of this code in code seg
  24. ; All values computed from offsets in codeseg need to be
  25. ; adjusted by adding CODEORG to each.  The obvious method,
  26. ; using "org CODEORG" causes MASM/LINK to fill in the space.
  27.  
  28. codeseg    segment
  29.     assume cs:codeseg, ds:codeseg
  30.  
  31. ; Initial program entry point
  32. ; (Assembler is told this is at offset zero.)
  33.  
  34. main:
  35.     ; Set up the stack
  36.     xor    ax,ax
  37.     mov    si,7C00h    ; just before load location
  38.     cli
  39.     mov    ss,ax
  40.     mov    sp,si
  41.     sti
  42.  
  43. ; Relocate this code from 0:7C00h to 0:CODEORG
  44.     mov    ds,ax
  45.     mov    es,ax
  46.     mov    si,7C00h    ; where this program is initially loaded
  47.     mov    di,CODEORG
  48.     mov    cx,0100h
  49.     cld
  50.     rep    movsw
  51.  
  52. ; Jump to relocated code (0:CODEORG)
  53.     jmp    far ptr begin1
  54. begin    equ    $    ; The above jump lands here.
  55.  
  56. ; Print partition menu from name table
  57. menu:
  58.     call    putnl        ; print newline
  59.     mov    si, offset pnames ; no org fix-up here!
  60.     mov    al, '1'
  61. prname:
  62.     push    si
  63.     push    ax
  64.  
  65.     call    putc
  66.     mov    al,' '
  67.     call    putc
  68.     mov    cx,8        ; maximum name length
  69.     call    putn
  70.     call    putnl
  71.  
  72.     pop    ax
  73.     pop    si
  74.     add    si,8
  75.     inc    al
  76.     cmp    al,'4'
  77.     jbe    prname
  78.  
  79. ; Prompt for and read user selection
  80. select:
  81.     call    putnl    ; print prompt
  82.     mov    si, offset prompt + CODEORG
  83.     call    puts
  84.  
  85.     mov    ah,0    ; Read a keystroke and print it
  86.     int    16h
  87.     push    ax
  88.     call    putc
  89.     call    putnl
  90.     pop    ax
  91.  
  92.     sub    al,'1'    ; range check and convert to index
  93.     cmp    al,04
  94.     jnb    select
  95.  
  96. boot:
  97. ; Boot from the selected partition.
  98. ; On entry to this section:  AL = index of ptable element
  99.  
  100.     ; get address of ptable element (si = & ptable[AL])
  101.     mov    si, offset ptable ; no org fix-up here
  102.     mov    cl,16    ; size of array element
  103.     mul    cl        ; ax = al * cl
  104.     add    si,ax
  105.  
  106. ; Check for valid system ID (non-zero)
  107.  
  108.     mov    al,[si+4]
  109.     cmp    al,0
  110.     jnz    id_ok
  111.     mov    si, offset msgempty + CODEORG
  112.     jmp    error
  113. id_ok:
  114.  
  115. ; Read first sector of selected partition into 0x7c00
  116. ; Also, mark this entry active (in RAM only) in case the
  117. ; secondary boot program looks at it (which it may).
  118.  
  119.     mov    al,80h    ; active flag
  120.     mov    [si], al
  121.     mov    cx,5    ; retry count
  122. retry:    push    cx
  123.     mov    dx,[si]    ; drive, head
  124.     mov    cx,[si+2]    ; cyl, sector
  125.     mov    bx,7C00h    ; destination (es=0)
  126.     mov    ax,0201h    ; BIOS read one sector
  127.     int    13h
  128.     jnc    rd_ok
  129.     xor    ax,ax    ; reset disk
  130.     int    13h
  131.     pop    cx
  132.     loop    retry
  133.     mov    si, offset msgread + CODEORG
  134.     jmp    error
  135. rd_ok:    pop    cx
  136.  
  137. ; Check for valid magic number in secondary boot sector
  138.     mov    ax, 0AA55h
  139.     assume    ds:seg0        ; Actually, codeseg == seg0
  140.     cmp    ax, magic2
  141.     assume    ds:codeseg
  142.     jz    magic_ok
  143.     mov    si, offset msginvalid + CODEORG
  144.     jmp    error
  145. magic_ok:
  146.  
  147. ; Make sure ds:si points to the booted partition, and
  148. ; Jump to the secondary boot program.
  149.     jmp    far ptr begin2
  150.  
  151. ; Jump here with si=error-message
  152. error:
  153.     call    puts
  154.     call    putnl
  155.     jmp    menu
  156.  
  157. ;*************************************************************
  158. ; Subroutines
  159. ;*************************************************************
  160. CR    EQU    13
  161. LF    EQU    10
  162. TAB    EQU     9
  163.  
  164. putc    proc    near        ; print char in AL
  165.     mov    ah, 0Eh        ; uses: ax, bx
  166.     mov    bx, 07
  167.     int    10h
  168.     ret
  169. putc    endp
  170.  
  171. putnl    proc    near        ; print a newline
  172.     mov    al, CR        ; uses: ax, bx
  173.     call    putc
  174.     mov    al, LF
  175.     call    putc
  176.     ret
  177. putnl    endp
  178.  
  179. puts    proc    near        ; print string at address SI
  180.     mov    cx,80        ; Stop at null or CX chars
  181. putn:    lodsb            ; uses: ax, bx, cx, si
  182.     cmp    al,0
  183.     jz    puts_e
  184.     push    cx
  185.     call    putc
  186.     pop    cx
  187.     loop    putn
  188. puts_e:    ret
  189. puts    endp
  190.  
  191. ;**********************************************************
  192. ; A little space here makes this program live happily with
  193. ; SpeedStor, which wants to write type-override stuff here.
  194. ;**********************************************************
  195.  
  196.     org    100h
  197. ;**********************************************************
  198. ; Strings
  199. ;**********************************************************
  200.  
  201. prompt        db    "Boot partition? (1-4) ",0
  202. msgempty    db    "Empty!",0
  203. msgread        db    "Read error!",0
  204. msginvalid    db    "Invalid!",0
  205.  
  206. codeseg    ends
  207.  
  208. ; Declares some offsets in segment zero
  209. seg0    segment    at 0
  210.  
  211.     org    CODEORG + (offset begin - offset main)
  212. begin1    equ    $
  213.  
  214. ; Here is the name table used for the partition menu.
  215. ; The accompanying fdisk program updates this table.
  216.     org    CODEORG + 180h
  217. pnames    db    32 dup(?)
  218.  
  219. ; The locations after 1AE are (reportedly) used by some
  220. ; Western Digital controllers in "auto-configure" mode.
  221. ; Don't put anything critical between here and ptable.
  222.  
  223. ; Here is the partition table
  224.     org    CODEORG + 1BEh
  225. ptable    db    (4 * 16) dup(?)
  226.  
  227. ; Here is where the secondary boot sector is loaded.
  228.     org    7C00h
  229. begin2    equ    $
  230.     org    7DFEh
  231. magic2    dw    ?
  232. seg0    ends
  233.  
  234.     end    main
  235.